package com.woniu.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.pojo.House;
import com.woniu.pojo.Leasefile;
import com.woniu.service.HouseService;
import com.woniu.service.TenancyService;

@RestController
@RequestMapping("tc")
public class TenancyController {
		@Autowired
	private TenancyService tenancyService;
		@Autowired
		private HouseService houseService;
	
	@RequestMapping("list")
	public Map<String,Object> getAllTenancy(Integer start,Integer length,Leasefile leasefile){
		//System.out.println("�����÷�ҳ������");
//		"recordsTotal": dt.data.recordTotal,
//      "recordsFiltered": dt.data.recordTotal,
//      "data":dt.data.list
		//PageHelper.startPage((start/length)+1, 2);
		
	//List<Leasefile> list= tenancyService.getAllTenancy();
		//PageInfo<Leasefile> pageInfo = new PageInfo<Leasefile>(list);
		PageInfo<Leasefile> pageInfo = tenancyService.getAllTenancyByPage((start/length)+1, length, leasefile);
		//System.out.println("----"+pageInfo);
	//Page page
		 Map<String,Object> map=new HashMap<String,Object>();
	        //����Ŀ��
	        map.put("recordsTotal", pageInfo.getTotal());
	        //����Ŀ��
	        map.put("recordsFiltered", pageInfo.getTotal());
	        //����
	        map.put("data", pageInfo.getList());
			return map;
		
	}
	@RequestMapping("deleteTenancyByid")
	public String deleteTenancyByid(Integer rf_id) {
		System.out.println();
		tenancyService.deleteTenancyByid(rf_id);
		return "删除成功";
	}
	@RequestMapping("deleteRegisterbooksById")
	public String deleteRegisterbooksById(String rf_ids) {
	
		tenancyService.deleteRegisterbooksById(rf_ids);
		return "删除"+rf_ids+"成功";
	}
	@RequestMapping("addTenancy")
	public String addTenancy(Leasefile leasefile) {
		//System.out.println(leasefile.toString());
		tenancyService.addTenancy(leasefile);
		return "添加成功";
	}
	@RequestMapping("getHouseId")
	public List getHouseId() {
		System.out.println();
		//tenancyService.deleteTenancyByid(rf_id);
		List list=houseService.getAllhouse();
		return list;
	}
	@RequestMapping("getHouseById")
	public House getHouseById(Integer h_id) {
		//System.out.println();
		//tenancyService.deleteTenancyByid(rf_id);
		House house=houseService.getHouseById(h_id);
		return house;
	}
	@RequestMapping("getHouseByhouse_id")
	public House getHouseByhouse_id(String house_id) {
		System.out.println("--------------");

		House house=houseService.getHouseByhouse_id(house_id);
		
		return house;
	}
	@RequestMapping("getUpdateTenancyInfo")
	public Leasefile getUpdateTenancyInfo(Integer rf_id) {
		System.out.println();

		Leasefile leasefile=tenancyService.getUpdateTenancyInfo(rf_id);
		return leasefile;
	}
	@RequestMapping("UpdateTenancyInfo")
	public String UpdateTenancyInfo(Leasefile leasefile) {
		//System.out.println("��������ҹ");

		tenancyService.UpdateTenancyInfo(leasefile);
		return "修改成功";
	}
}
